import axios from 'axios';
import qs from 'qs';

axios.defaults.timeout = 5000;
axios.defaults.baseURL = '';

export function get(url: string, params: object) {
    return new Promise((resolve, reject) => {
		axios.get(url, {
			params: params
		}).then(response => {
			resolve(response.data);
		}).catch(err => {
			reject(err);
		});
	});
}

export function postformdata(url: string, params: object) {
    return new Promise((resolve, reject) => {
		axios.post(url, qs.stringify(params)).then(response => {
			resolve(response.data);
		}).catch(err => {
			reject(err);
		});
	});
}

export function post(url: string, params: object, formdataFlag: boolean) {
    if(formdataFlag) {
		return postformdata(url, params);
	}
	return new Promise((resolve,reject) => {
		axios.post(url, params).then(response => {
			resolve(response.data);
		}).catch(err => {
			reject(err);
		});
	})
}